Ext.namespace('VAS');
VAS.AuditPanel = Ext.extend(Ext.FormPanel, {
	initComponent : function() {
		var config={						
			width         : '100%', 
            frame         : true,    
		    minButtonWidth: 50,
            layout        : 'column',
            bodyStyle      : 'padding:5px 15px 0 ',
			items:[{
				columnWidth : 1,
				layout      : 'form',
				border      : false,
				items       : [
					{
						labelStyle      : "width:106px;text-align:left",
						id				: 'filbeforekey',
						name            : 'filbeforekey',
						xtype           : 'label',
						fieldLabel      : '用到的敏感字有'
	                    ,width          : 720
	                    ,hidden  		: true
	                     ,hideLabel		: true

			 		},
					{
						labelStyle      : "width:106px;text-align:left;color:red",
						id				: 'idea',
						name            : 'idea',
						xtype           : 'textarea',
						fieldLabel      : '审核意见',
						allowBlank		:false,
						blankText		:'请填写审核意见'
						,autoScroll     : true
	                    ,width          : 720,
	                    height         : 23
					}
				]
			}]
		};
		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);
		VAS.AuditPanel.superclass.initComponent.apply(this, arguments);
	}
	,afterRender:function(){
		VAS.AuditPanel.superclass.afterRender.apply(this,arguments);
		 if(this.viewUrl!=='undefined'){
		 	
		 	this.getForm().findField('idea').setValue('aa');
//			 	this.load({url:this.viewUrl,params:this.postdata});
		 }

	}
})
VAS.AuditWindow = function($config) {
	
	var _this = this;
	_this.$config = $config;  
	_this.callback=function(){
		$config.grid.reload();
	    _this.close();
	};
	  
	_this.getPostdata=function(){
  		var postData=_this.auditPanel.getForm().getValues();	  
  	 	Ext.apply(postData,$config.postData);	  	
		return postData;
	}
	var thisConfig={};
	var view_url =$config.postData.view_url;
	
    _this.contentForm = new Ext.Panel({
        frame:true,
		html: '<iframe id=mainframe src='+view_url+' frameborder=0  height=513 width=100%   ></iframe>' //scrolling=yes  
//		autoHeight:true,
//		border:true,
//		split: true,
		,height : 513
	});

	_this.auditPanel = new VAS.AuditPanel({url:$config.saveUrl,viewUrl:$config.viewUrl,postdata:_this.getPostdata});
	if($config.viewUrl===''){   
		 thisConfig = {
			items : [_this.contentForm, _this.auditPanel]
			,buttons:[
				{
					xtype:'button',
					id   : 'articlePicButton',
					text    : '图片列表',
			//    	hidden  : true,
			    	handler : function() {
						var picgrid = new VAS.ArticlePicGridWin({content_id:$config.postData.content_id
						
						});
			    		picgrid.show();
			
			    	}
				},
			    
				{
	            	xtype:'comButton',
	            	text:'驳回',
	            	actionType:'confirm'
	            	,owner:_this,
	            	action:$config.saveUrl+'refuse.action'
	            	,callback:_this.callback
	                ,postdata:_this.getPostdata
	            	,form:_this.auditPanel
			    },{
	            	xtype:'comButton',
	            	text:'通过',
	            	actionType:'confirm'
	            	,owner:_this,
	            	action:$config.saveUrl+'agree.action'
	            	,callback:_this.callback
	            	,postdata:_this.getPostdata
	            	,form:_this.auditPanel
			    },{
	            	xtype:'comButton',
	            	text:'关闭',
	            	actionType:'close'
	            	,owner:_this,
	            	action:''
	               ,callback:_this.callback
	               ,postdata:{}
	               ,form:_this.auditPanel
			    }]
		};
	 }else{
		thisConfig = {
			items : [_this.auditPanel]
			,buttons:[
				{
	            	xtype:'comButton',
	            	text:'关闭',
	            	actionType:'close'
	            	,owner:_this,
	            	action:''
	               ,callback:_this.callback
	               ,postdata:{}
	               ,form:_this.auditPanel
			    }]
		};
	 }

	var _config = $config || {};
	Ext.apply(_this, Ext.apply(thisConfig, _config));
	VAS.AuditWindow.superclass.constructor.call(_this);

};
Ext.extend(VAS.AuditWindow,Ext.Window,{	
	manager:wgroup,
	
	loadForm:function(){
		this.items.itemAt(0).load({
			    waitTitle   : '正在加载中...',
				waitMsg     : '正在向服务器发送请求', 
	 			url         : this.$config.loadUrl,
	 			success     : function(form,action) {	
	 				if (action.result.data["authorizeState"] == 1) {
	 					Ext.getCmp("productCode").setDisabled(false);
	 				}
	 				
//	 				Ext.getCmp("tiltePhoto").setValue("");
	 				var tiltePhotoName = action.result.data["tiltePhotoName"];
	 				var tiltePhotoDesc = Ext.getCmp("tiltePhotoDesc");
	 				if (tiltePhotoName != "" && tiltePhotoName != "null"  && tiltePhotoName != undefined) {
	 					tiltePhotoDesc.setValue("<font size='2' color='red'><a href=javascript:exportFile('admin/article/ArticleAction!exportFile.action?id='+Ext.getCmp('id').getValue()+'&type=titlephoto')>"+tiltePhotoName+"</a>");
	 				}
	 				
//	 				Ext.getCmp("contentPhoto").setValue("");
	 				var contentPhotoName = action.result.data["contentPhotoName"];
	 				var contentPhotoDesc = Ext.getCmp("contentPhotoDesc");
	 				if (contentPhotoName != "" && contentPhotoName != "null"  && contentPhotoName != undefined) {
	 					contentPhotoDesc.setValue("<font size='2' color='red'><a href=javascript:exportFile('admin/article/ArticleAction!exportFile.action?id='+Ext.getCmp('id').getValue()+'&type=contentphoto')>"+contentPhotoName+"</a>");
	 				}
	 				
//	 				Ext.getCmp("audio").setValue("");
	 				var audioName = action.result.data["audioName"];
	 				var audioDesc = Ext.getCmp("audioDesc");
	 				if (audioName != "" && audioName != "null"  && audioName != undefined) {
	 					audioDesc.setValue("<font size='2' color='red'><a href=javascript:exportFile('admin/article/ArticleAction!exportFile.action?id='+Ext.getCmp('id').getValue()+'&type=audio')>"+audioName+"</a>");
	 				}
	 				
	 				var content = action.result.data["content"];
	 				var contentTab  = Ext.getCmp("contentTab");
	 				var pattern = /<\/?[^>]+>|&[^;]*;/gi;
	 				if (!pattern.test(content)) {
	 					contentTab.setActiveTab(1);
	 					Ext.getCmp("content2").setValue(content);
	 				} else {
	 					contentTab.setActiveTab(0);
	 					Ext.getCmp("content1").setValue(content);
	 				}
	 				
	 				Ext.getCmp('idea').focus();
	 				
			 		Ext.getCmp("author").setReadOnly(true);
					Ext.getCmp("isCommend1").setReadOnly(true);
					Ext.getCmp("authorizeState").setReadOnly(true);
					Ext.getCmp("title").setReadOnly(true);
					Ext.getCmp("origin").setReadOnly(true);
					Ext.getCmp("videoCode").setReadOnly(true);
					Ext.getCmp("productCode").setReadOnly(true);
					Ext.getCmp("sdUrl").setReadOnly(true);
					Ext.getCmp("hdUrl").setReadOnly(true);
					Ext.getCmp("tiltePhoto").setReadOnly(true);
					Ext.getCmp("contentPhoto").setReadOnly(true);
					Ext.getCmp("audio").setReadOnly(true);
					Ext.getCmp("contentHDTemplate").setReadOnly(true);
					Ext.getCmp("contentSDTemplate").setReadOnly(true);
					Ext.getCmp("keyword").setReadOnly(true);
					Ext.getCmp("content1").setReadOnly(true);
					Ext.getCmp("content2").setReadOnly(true);
	 				
	 			},
	 			failure     : function(form,action) {
	 				Ext.Msg.alert("失败",action.result.msg);
	 			},
	 			params      : {
	 				data    : Ext.util.JSON.encode(this.$config.postData)
	 			}
	 	});

	}

	,loadKeyFilterReport:function(){
	    Ext.Ajax.request({
			url     : 'admin/audit/auditRecord!getKeyFilterReport.action',
			success : function(response, options) {
		   		//检查session是否过期
		    	checkTimeOut(response);
				var responseObj = Ext.util.JSON.decode(response.responseText);
				if (responseObj.success) {
					var key = responseObj.filbeforekey
					if(key.length > 0){
						key = "用到的敏感字有:        " + key;
						Ext.getCmp('filbeforekey').setValue(key);
						Ext.getCmp('filbeforekey').setVisible(true);
						Ext.getCmp('filbeforekey').show ();
					}
					
				}else{
					alertFailure(responseObj);
				}
			},
			failure : function(response, options) {
				Ext.Msg.alert('提示','服务器异常！');
			},
			params  : this.$config.postData
		})
	}
	
	
});

